#include "qdriveattribute.h"

QDriveAttribute::QDriveAttribute(const QString &name, const QString &info, QObject *parent):
    QObject(parent),
    m_name(name),
    m_information(info),
    m_value("")
{
}

QVariant QDriveAttribute::attribute(const QString &key, const QVariant &def)
{
    return m_attribute.value(key,def);
}

void QDriveAttribute::setAttribute(const QString &key, const QVariant &value)
{
    m_attribute.insert(key,value);
}

QString QDriveAttribute::name()
{
    return m_name;
}

QString QDriveAttribute::information()
{
    return m_information;
}

void QDriveAttribute::setValue(const QVariant &value)
{
    if(m_value!=value)
    {
        m_value=value;
        emit valueChanged();
    }
}

QVariant QDriveAttribute::value()
{
    return m_value;
}

QString QDriveAttribute::valueText()
{
    return m_value.toString();
}

QIcon QDriveAttribute::valueIcon()
{
    return QIcon();
}

void QDriveAttribute::read(QXmlStreamReader &r)
{
    for(bool finished=false;!finished && !r.hasError();)
    {
        switch(r.readNext())
        {
        case QXmlStreamReader::StartElement:
            break;
        case QXmlStreamReader::EndElement:
            finished=true;
            break;
        case QXmlStreamReader::Characters:
            setValue(r.text().toString());
            break;
        default:
            break;
        }
    }
}

void QDriveAttribute::write(QXmlStreamWriter &w)
{
    w.writeCharacters(m_value.toString());
}


QDriveStringAttribute::QDriveStringAttribute(const QString &name, const QString &info, QObject *parent):
    QDriveAttribute(name,info,parent)
{
    setAttribute("Editor_Type","LineEdit");
}

QDriveNumberAttribute::QDriveNumberAttribute(const QString &name, const QString &info, QObject *parent):
    QDriveAttribute(name,info,parent)
{
    setAttribute("Editor_Type","SpinBox");
}


QDriveEnumAttribute::QDriveEnumAttribute(const QString &name, const QString &info, QObject *parent):
    QDriveAttribute(name,info,parent)
{
    setAttribute("Editor_Type","ComboBox");
}
